package mianshi.sort;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/06/01 08:05
 */
public class QuickSort {
    public static void main(String[] args) {

    }

    public void quickSort(int[] arr, int start, int end) {
        if (start >= end) {
            return;
        }
        int prvotIndex = partition(arr, start, end);
        quickSort(arr, start, prvotIndex - 1);
        quickSort(arr, prvotIndex + 1, end);
    }

    public int partition(int[] arr, int start, int end) {
        int pivot = arr[start];
        int left = start;
        int right = end;
        while (left != right) {
            while (left < right && arr[left] < pivot) {
                left++;
            }
            while (left < right && arr[right] > pivot) {
                right--;
            }
            if (left < right) {
                int p = arr[left];
                arr[left] = arr[right];
                arr[right] = p;
            }
        }
        arr[start] = arr[left];
        arr[left] = pivot;
        return left;
    }
}
